package mapping;

import generation.scale.Scale;
import generation.scale.ScaleFactory;

import java.util.Hashtable;

import processing.core.PApplet;

public class TwitterNoteMapping {

	public static String getTuneFromLetter(Scale scale, String letter){
		String letters = "abcdefghijklmnopqrstuvwxyz0123456789@#()";
		int size = scale.getTunes().length;
		Hashtable<String, Integer> map = new Hashtable<String, Integer>();
				
		int division = letters.length() / size;
		
		int ind = 0;
		for (int i = 0; i < letters.length(); i++) {
			map.put(letters.substring(i, i+1), ind);
			if(i % division == (division - 1)){
				ind = ind+1;
			}
		}
		
		int index = 0;
		String key = letter.toLowerCase();
		
		if(map.containsKey(key)){
			index = map.get(key);
		}
		
		return scale.getTunes()[index];
	}
	
	public static String getDurationFromSize(int wordSize, int minSize, int maxSize){
		String durations = "hqis";
		int mapping = (int) Math.floor(PApplet.map(wordSize, minSize, maxSize, 0, durations.length()-1));
		return durations.substring(mapping, mapping + 1);
	}
	
	public static int getValueDuration(String duration){
		Hashtable<String, Integer> map = new Hashtable<String, Integer>();
		//map.put("w", 16);
		map.put("h", 8);
		map.put("q", 4);
		map.put("i", 2);
		map.put("s", 1);
		return map.get(duration);
	}
	
	public static String getChordsFromLetter(String letter, Scale scale){
		String chord = "";
		String letterFrequency = "etaoinshrdlcumwfgypbvkjxqz";
		String chords[] = scale.getChords();
		Hashtable<String, String> map = new Hashtable<String, String>();
		for (int i = 0; i < chords.length; i++) {
			map.put(letterFrequency.substring(i, i+1), chords[i]);
		}
		if(map.containsKey(letter)){
			chord = map.get(letter);
		}
		return chord;
	}
	
	public static void main(String[] args) {
		Scale scale = ScaleFactory.getScale("pentmaj");
		System.out.println(getChordsFromLetter("t", scale));
	}
	
}
